home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.sprintlink.net!news1!news
- From: rclark@iquest.net (Robert B. Clark)
- Subject: Re: ???Recursive Function needed for string printing
- X-Nntp-Posting-Host: ind-009-237-105.iquest.net
- Message-ID: <31190090.624002@news.iquest.net>
- Sender: news@iquest.net (News Admin)
- Organization: IQuest Internet, Inc.
- X-Newsreader: Forte Agent .99d/16.182
- References: <4f44eo$74u@upsidedown.MTS.Net>
- Date: Wed, 7 Feb 1996 19:46:30 GMT
-
- On Mon, 05 Feb 1996 07:26:19 GMT, bwilliam@MTS.Net (George) wrote:
-
- >How do I write a recursive function to print a string using only
- >printf and %c to print it out.
-
- Something like this...
-
- /* rstring.c - Recursively print character array string */
- /* R Clark <rclark@iquest.net> 7 Feb 1996 */
-
- #include <stdio.h>
- #include <stdlib.h>
-
- void recurseString(char *s)
- /* Recursively prints head character until head char==\0 */
- {
- if (*s!='\0') { /* Exit condition */
- putchar(*s); /* Or printf("%c",*s) if you prefer */
- recurseString(++s); /* Increment char pointer, recurse */
- }
- }
-
- int main(void)
- {
- puts("\nRecursive string print:");
- recurseString("This string will be printed recursively.");
- return EXIT_SUCCESS;
- }
- --
- Robert B. Clark <rclark@iquest.net>
- "Always listen to experts. They'll tell you what can't be done, and why. Then do it." --RAH
-